package com.yilin.platform.base_core.application;


import com.yilin.platform.base_core.commons.encrypt.Md5Util;
import com.yilin.platform.base_core.components.redis.RedisClient;
import com.yilin.platform.base_core.components.redis.RedisKeys;

public class ServiceUtil {


    //服务通讯安全 保存 ,notifyMethodName：被通知的方法名称
    public static String saveServiceSafeNotify(String notifyMethodName) {
        String md5pass = Md5Util.md5(AppUtil.getUUID());
        RedisClient.getInstance().hset(RedisKeys.SERVICE_SAFE_KEY,notifyMethodName, md5pass);
        return md5pass;
    }

    //服务通讯安全 校验
    public static Boolean verifyServiceSafeNotify(String notifyMethodName,String md5pass){
        try {
            if (notifyMethodName == null) return false;
            if (md5pass == null) return false;
            String _md5pass = RedisClient.getInstance().hget(RedisKeys.SERVICE_SAFE_KEY, notifyMethodName);
            if (_md5pass == null) return false;
            RedisClient.getInstance().hdel(RedisKeys.SERVICE_SAFE_KEY,notifyMethodName);
            return md5pass.equals(_md5pass);
        }catch (Exception e){
            return false;
        }
    }

}
